﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.CMS.Plugins;
using MethodWorx.CMS.TemplateLanguage.Parsers;
using MethodWorx.CMS.TemplateLanguage.Parsers.Html;
using MethodWorx.CMS.TemplateLanguage.Parsers.Content;

namespace MethodWorx.CMS.TemplateLanguage
{
    public static class DefaultParserFactory
    {
        private static List<IParser> parsers = new List<IParser>();

        static DefaultParserFactory()
        {
            foreach (var type in typeof(DefaultParserFactory).Assembly.GetTypes())
            {
                if (typeof(IParser).IsAssignableFrom(type) && !type.IsAbstract)
                    parsers.Add((IParser)Activator.CreateInstance(type));
            }

        }

        public static void Add(IParser parser)
        {
            parsers.Add(parser);
        }

        public static IEnumerable<IParser> GetParsers()
        {
            return parsers.Where(p => !string.IsNullOrEmpty(p.Name) && !string.IsNullOrEmpty(p.Namespace));
        }

    }
}
